const https = require('https');
const fs = require('fs');
const path = require('path');
const app = require('./app');

// HTTPS 配置
const httpsOptions = {
  key: fs.readFileSync(path.join(__dirname, 'cert/key.pem')),
  cert: fs.readFileSync(path.join(__dirname, 'cert/cert.pem'))
};

// 创建 HTTPS 服务器
const server = https.createServer(httpsOptions, app);

// 监听 443 端口
const PORT = process.env.PORT || 443;
server.listen(PORT, () => {
  console.log(`HTTPS server running on port ${PORT}`);
  console.log(`访问地址: https://localhost:${PORT}`);
});

// 错误处理
server.on('error', (error) => {
  console.error('HTTPS server error:', error);
}); 